/**************************************************************************
 * @doc EMV
 * @module EMVsrc |  
 * Source code for the EMV handling functions.
 *
 * Product         :   SoftPay 2000 (Global Payment Methodology).
 * <nl>Developer   :   SoftPay Development Team ASPAC ADC.
 * <nl>Notes       :
 *
 * @head3 EMV Functions | 
 * @index | EMV
 * @end
 *
 * Copyright (c) 1996-2005 by VeriFone Inc. All rights reserved.
 * 
 * No part of this software may be used, stored, compiled, reproduced,
 * modified, transcribed, translated, transmitted, or transferred, in any form 
 * or by any means whether electronic, mechanical, magnetic, optical, 
 * or otherwise, without the express prior written permission of VeriFone, Inc.
 *
 * Revision History
 * ------------------------------------------------------------------------
 *
 *
 ********************************************************************************/
/********************************/
/* Internal Use for this EMVAPI */
/********************************/
//KiaSoon 03022006: AEIPS DR044 CASE
#define AUTO_CANCELLED  158

//void vdPromptManager(int inCondition);
void vdPromptManager(unsigned short usCondition);

//void vdPromptRemoveManager(int inCondition);
void vdPromptRemoveManager(unsigned short usCondition);
int inDisplayOverrideChipScrn(void);
void vdEMVDisplayErrorMsg(EMVResult val);
void vdDisplayFallbackMsg(TRANSACTION_OBJECT *pobTran);
int createScriptFiles(byte *buffer);
EMVBoolean bIsCardBlackListed(byte * pan, unsigned short panLen, byte * panSeqNo, unsigned short panSeqLen);
char inGetOption(void);
short shGetAutoSelectFlag(void);
int inMenuFunc(char **labels, int numLabels);
unsigned short usAmtEntryFunc(unsigned long *lnAmountValue);
void vdSetCDTSignLine(VS_BOOL fSignLine);

//?????KF --- prototype may be define in some .h file of emvapp
//			  But implementation should be done in customer application
//			  NOT SURE, need to check
int readRecord(int fHandle , char *buf);
char chConvertKey(char key);
char chGetKeyPress(void);
void vdFlushKeyboard(void);
int inEMVPPcom(char *command, char *answer, char complex);
int inEMVPPPresent(void);
short getPPUsrPin(unsigned char * pstPin, unsigned char *CKclear, unsigned char *CKencr, int *index);
int inEMVGetPin(char *buffer, char *key, char *mk, int index, char *msg1, char *msg2, char *msg3);
int   inPINValidator(char *pstPIN);
short getTermUsrPin(unsigned char *pin);
int inDefaultGetPTID(char *ptid);
int inEMVGetTermID(char * pchTermID);
int inOnlinePINFunc(void);
EMVBoolean bUpdateLogforSplitSales(void);
unsigned long ulCheckSplitSalesAmt(void);

/***************************************/
/* Call back functions for EMV library */
/***************************************/
/*** No need to define here, since it is define the prototype in EMV library */
/*   But the function should be implement by the customer application */
short getUsrPin(unsigned char *pin);
EMVResult getLastTxnAmt(Ulong *amt);
EMVResult usEMVIssAcqCVM(unsigned short issacq, unsigned short *code);
unsigned short usEMVPerformOnlinePIN(void);
unsigned short usEMVPerformSignature(void);
void usEMVDisplayErrorPrompt(unsigned short errorID);
void vdSetEMVOnlineCondition(TRANSACTION_OBJECT *pobTran, int inPipResult);
int inEMVGetTimeDiff(char* pchTime1, char* pchTime2);
int inEMVResetForceOnlineTime(TRANSACTION_OBJECT *pobTran);
int inEMVSetAuthFloorLimit(TRANSACTION_OBJECT *pobTran);

/* ?????KF -- I think it the following may need to define the prototype here
			  But those function is implement in the EMV library or toolkit
			  */
extern void hex_2_asc(BYTE *outp, BYTE *inp, int length);
extern void ascii_to_bin(BYTE *dest, BYTE *src, int length);
extern int getNextRawTLVData(unsigned int *tag, byte *data, const byte *buffer);
extern int getNextRawTLV(unsigned int *tag, byte *data, const byte *buffer);
void get_unpredict(BYTE *inpbuff, int size);
unsigned char LRC(char *buffer, int len);

extern int inEMVReferralProcessing(TRANSACTION_OBJECT *pobTran);
extern int inEMVDisplaySigReqd(TRANSACTION_OBJECT *pobTran);
extern int inWaitKey(int inSeconds);
extern void vdGetMessageFromFile(long lnMessageIndex, char *szMessageBuffer);
extern void vdDisplayAt(int x, int y, const char *m, int o);

typedef struct TagCAPKFILE_LIST_REC				// Added for PK file revocation
{
	char szCAPKFileName[EMV_PK_FILE_NAME + 1];
}	CAPK_FILE_LIST_REC;

#define CAPK_FILE_LIST_FILENAME				"CAPKLIST.DAT"
#define FILE_LIST_FILENAME_SIZE				sizeof(CAPK_FILE_LIST_REC)

int inApplnESTVerifyAllCAPKs(void);
int inApplnCreateFileList(void);
int inApplnPKFIleNameCompFunc (char* pszCAPKFileName1, char *pszCAPKFileName2);
int inApplnCheckAndCleanPKFiles(void);
int inApplnESTVerifyCAPKFile(char *szCAPKFileName);
extern void vdEMVSetFallbackTime(void);
extern int inEMVResetFallBackTime(TRANSACTION_OBJECT *pobTran);
extern int inEMVCheckFallBackTime(TRANSACTION_OBJECT *pobTran);

//KiaSoon 03022006: To Fix AEIPS APPL SELECT PROBLEM-EDR44
#define MAX_APP_LABEL 15
typedef struct TagMenuLabel
{
  	int inOriginalLabel[MAX_APP_LABEL];
  	int inApplSelected[MAX_APP_LABEL];
  	int inMapLabel[MAX_APP_LABEL];
}LABEL_REC;

void vdResetApplLabel(void);
void vdSetApplLabelSelect(int inLabel);
void vdInitLabelTable(int inLabel);
void vdGenerateMap(int inLabel);
int inRtrnMenuLabel(int inNumLabels);
int inRtrnOriginalLabel(int inMapLabel);